const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require("path")

module.exports = {
  devServer: {
    port: 3000, // 端口号
    open: true

  },
  entry: "./src/main.js", // 入口
  output: {
    path: path.join(__dirname, "dist"), // 出口路径
    filename: "bundle.js" // 出口文件名
  },
  // 打包模式
  mode: "production",
  //自动生成html文件配置
  plugins: [new HtmlWebpackPlugin({
    template: "./public/index.html"
  })],

  //打包css的一些配置
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.less$/i,
        use: [
          // compiles Less to CSS
          'style-loader',
          'css-loader',
          'less-loader',
        ],
      },
      //打包图片
      {
        test: /\.(png|jpg|gif|jpeg)$/i,
        type: 'asset'
      },

      { // webpack5默认内部不认识这些文件, 所以当做静态资源直接输出即可
        test: /\.(eot|svg|ttf|woff|woff2)$/,
        type: 'asset/resource',
        generator: {
          filename: 'font/[name].[hash:6][ext]'
        }
      },
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'] // 预设:转码规则(用bable开发环境本来预设的)
          }
        }
      }


    ],
  },

}